package com.kabuda.zhugehot200;

/**
 * @author kabuda
 * @date 2025-03-15 15:49
 * @description
 */
public class t26_删除排序数组重复项 {
    public static void main(String[] args) {
        System.out.println(removeDuplicates(new int[]{0,0,1,1,1,2,2,3,3,4}));
    }

    /**
     * 双指针
     *
     * @param nums
     * @return
     */
    public static int removeDuplicates(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        //慢指针
        int i = 0;
        //快指针
        for (int j = 1; j < nums.length; j++) {
            //如果不相等，慢指针+1，将快指针的值给慢指针
            if(nums[i]!=nums[j]){
                i++;
                nums[i]=nums[j];
            }
        }
        return i+1;
    }
}
